//
//  SAStatisticsVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/4/7.
//

#import "SAStatisticsVC.h"
#import "SASaleDocumentsVC.h"
#import "SAWarehousingDocumentsVC.h"
#import "SAInventoryListVC.h"
#import "SAReturnDocumentsVC.h"
#import "SAStatisticsBusinessVC.h"
#import "SAStatisticsManagementVC.h"
#import "SAStatisticsTopUpVC.h"
#import "SAStatisticsResultsVC.h"
#import "SAStatisticsCommissionVC.h"
#import "SAStatisticsSummaryVC.h"
#import "SAPayDocumentsVC.h"
#import "SASettlementDocumentsVC.h"
#import "SAAllocateDocumentsVC.h"
#import "SAOperatingProfitVC.h"
#import "SAStatisticsSaleVC.h"
#import "SAStatisticsProfitVC.h"

@interface SAStatisticsVC ()

@end

@implementation SAStatisticsVC
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - event
-(void)clickedIconBtn:(UIButton *)sender {
    
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    
    NSString *isWarehousing = [NSString stringWithFormat:@"%@",menuList[2][@"isDelete"]];
    NSString *purchaseReceipt = [NSString stringWithFormat:@"%@",menuList[2][@"perms"][@"purchaseReceipt"]];
    
    NSString *inventory = [NSString stringWithFormat:@"%@",menuList[3][@"isDelete"]];
    NSString *stockCountingDocuments = [NSString stringWithFormat:@"%@",menuList[3][@"perms"][@"stockCountingDocuments"]];

    NSString *isOrder = [NSString stringWithFormat:@"%@",menuList[4][@"isDelete"]];
    NSString *orderOrderList = [NSString stringWithFormat:@"%@",menuList[4][@"perms"][@"orderOrderList"]];
    NSString *orderReturnList = [NSString stringWithFormat:@"%@",menuList[4][@"perms"][@"orderReturnList"]];
    
    NSString *statisticsBusinessSummary = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsBusinessSummary"]];
    NSString *statisticsSalesStatistics = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsSalesStatistics"]];
    NSString *statisticsRecharge = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsRecharge"]];
    NSString *statisticsPersonnelPerformance = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsPersonnelPerformance"]];
    NSString *statisticsEmployeeCommission = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsEmployeeCommission"]];
    NSString *statisticsExpenditureSummary = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsExpenditureSummary"]];
    NSString *statisticsViewOperatingProfit = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"statisticsViewOperatingProfit"]];
    NSString *actualSalesAmount = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"actualSalesAmount"]];
    
    NSString *isSaveDispatch = [NSString stringWithFormat:@"%@",menuList[10][@"isDelete"]];
    NSString *transferOrder = [NSString stringWithFormat:@"%@",menuList[10][@"perms"][@"transferOrder"]];
    NSString *distributionOrder = [NSString stringWithFormat:@"%@",menuList[10][@"perms"][@"distributionOrder"]];

    switch (sender.tag) {
        case 0:
            if ([statisticsBusinessSummary isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有经营概括权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAStatisticsBusinessVC new] animated:YES];
            break;
        case 1:
            if ([statisticsSalesStatistics isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有销售统计权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAStatisticsManagementVC new] animated:YES];
            break;
        case 2:
            if ([statisticsRecharge isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有充值统计权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAStatisticsTopUpVC new] animated:YES];
            break;
        case 3:
            if ([statisticsPersonnelPerformance isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有人员业绩权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAStatisticsResultsVC new] animated:YES];
            break;
        case 4:
            if ([statisticsEmployeeCommission isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有员工提成权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAStatisticsCommissionVC new] animated:YES];
            break;
        case 5:
            if ([statisticsExpenditureSummary isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有支出汇总权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAStatisticsSummaryVC new] animated:YES];
            break;
        case 6://销售单据
            if ([isOrder isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有订单权限,请联系店长添加" duration:2];
                break;
            }else if ([orderOrderList isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有销售单据权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SASaleDocumentsVC new] animated:YES];
            break;
        case 7://入库单据
            if ([isWarehousing isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有入库权限,请联系店长添加" duration:2];
                break;
            }else if ([purchaseReceipt isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有入库单据权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAWarehousingDocumentsVC new] animated:YES];
            break;
        case 8://盘点单据
            if ([inventory isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有库存权限,请联系店长添加" duration:2];
                return;
            }else if ([stockCountingDocuments isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有盘点单据权限,请联系店长添加" duration:2];
                return;
            }
            [self.navigationController pushViewController:[SAInventoryListVC new] animated:YES];
            break;
        case 9://退货单据
            [self.navigationController pushViewController:[SAStatisticsProfitVC new] animated:YES];
            break;
        case 10://配货单据
            if ([isSaveDispatch isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有调配货权限,请联系店长添加" duration:2];
                break;
            }else if ([distributionOrder isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有查看配货单据权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController: [[SAAllocateDocumentsVC alloc] initWithType:@"1"] animated:YES];
            break;
        case 11://调货单据
            if ([isSaveDispatch isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有调配货权限,请联系店长添加" duration:2];
                break;
            }else if ([transferOrder isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有查看调货单据权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController: [[SAAllocateDocumentsVC alloc] initWithType:@"2"] animated:YES];
            break;
        case 12://退货单据
            if ([isOrder isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有订单权限,请联系店长添加" duration:2];
                break;
            }else if ([orderReturnList isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有退货列表权限,请联系店长添加" duration:2];
                break;
            }
            [self.navigationController pushViewController:[SAReturnDocumentsVC new] animated:YES];
            break;
        case 13://收款单据
            [self.navigationController pushViewController:[SAPayDocumentsVC new] animated:YES];
            break;
        case 14://结算单据
            [self.navigationController pushViewController:[SASettlementDocumentsVC new] animated:YES];
            break;
        case 15://营业利润
            if ([statisticsViewOperatingProfit isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有营业利润权限,请联系店长添加" duration:2];
                return;
            }
            if ([actualSalesAmount isEqualToString:@"1"]) {
                [Prompt popPromptViewWithMsg:@"您没有实销额权限,请联系店长添加" duration:2];
                return;
            }
            [self.navigationController pushViewController:[SAOperatingProfitVC new] animated:YES];
            break;
        case 16://商品销售
            [self.navigationController pushViewController:[[SAStatisticsSaleVC alloc] initWithType:@"0"] animated:YES];
            break;
        case 17://商品明细
            [self.navigationController pushViewController:[[SAStatisticsSaleVC alloc] initWithType:@"1"] animated:YES];
            break;
        default:
            break;
    }
}

#pragma mark - initUI
-(void)initUI {
    [self setTitle:@"统计报表"];
    [self setBgImage:nil];
    self.view.backgroundColor = kBgColor;
    
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight, kBaseScreenWidth, 268)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UIView *buleView = [[UIView alloc] initWithFrame:SARectMake(20, 10, 4, 20)];
    buleView.backgroundColor = kBuleColor;
    [whiteView addSubview:buleView];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:SARectMake(41, 0, 100, 40)];
    titleLab.text = @"经营";
    titleLab.textColor = kBlackColor;
    titleLab.font = kFont(16);
    [whiteView addSubview:titleLab];
    
    UIView *line = [[UIView alloc] initWithFrame:SARectMake(0, 40, kBaseScreenWidth, 1)];
    line.backgroundColor = kLineColor;
    [whiteView addSubview:line];
   
    NSArray *imageArr = @[@"SA_business", @"SA_management", @"SA_topUp"];
    NSArray *titleArr = @[@"经营概括", @"销售统计", @"充值统计"];
    for (int i = 0; i < 3; i++) {
        UIImageView *iconImageV = [[UIImageView alloc] initWithFrame:SARectMake(47.5 + i * 125, 50, 30, 30)];
        iconImageV.image = [UIImage imageNamed:imageArr[i]];
        [whiteView addSubview:iconImageV];
        
        UILabel *iconLab = [[UILabel alloc] initWithFrame:SARectMake(i * 125, 90, 125, 20)];
        iconLab.textColor = kBlackColor;
        iconLab.text = titleArr[i];
        iconLab.font = kFont(15);
        iconLab.textAlignment = NSTextAlignmentCenter;
        [whiteView addSubview:iconLab];
        
        UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.tag = i;
        iconBtn.frame = SARectMake(i * 125, 41, 125, 75);
        [iconBtn addTarget:self action:@selector(clickedIconBtn:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:iconBtn];
    }
    
    UIView *line2 = [[UIView alloc] initWithFrame:SARectMake(0, 116, kBaseScreenWidth, 1)];
    line2.backgroundColor = kLineColor;
    [whiteView addSubview:line2];
    
    NSArray *imageArr2 = @[@"SA_results", @"SA_commission", @"SA_summary"];
    NSArray *titleAr2 = @[@"人员业绩", @"员工提成", @"支出汇总"];
    for (int i = 0; i < 3; i++) {
        UIImageView *iconImageV = [[UIImageView alloc] initWithFrame:SARectMake(47.5 + i * 125, 126, 30, 30)];
        iconImageV.image = [UIImage imageNamed:imageArr2[i]];
        [whiteView addSubview:iconImageV];
        
        UILabel *iconLab = [[UILabel alloc] initWithFrame:SARectMake(i * 125, 166, 125, 20)];
        iconLab.textColor = kBlackColor;
        iconLab.text = titleAr2[i];
        iconLab.font = kFont(15);
        iconLab.textAlignment = NSTextAlignmentCenter;
        [whiteView addSubview:iconLab];
        
        UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.tag = i + 3;
        iconBtn.frame = SARectMake(i * 125, 127, 125, 75);
        [iconBtn addTarget:self action:@selector(clickedIconBtn:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:iconBtn];
    }
    
    UIView *line10 = [[UIView alloc] initWithFrame:SARectMake(0, 192, kBaseScreenWidth, 1)];
    line10.backgroundColor = kLineColor;
    [whiteView addSubview:line10];
    
    NSArray *imageArr6 = @[@"SA_operatingProfit", @"SA_commoditySales", @"SA_goodsDetail"];
    NSArray *titleAr6 = @[@"营业利润", @"商品销售", @"商品明细"];
    for (int i = 0; i < imageArr6.count; i++) {
        UIImageView *iconImageV = [[UIImageView alloc] initWithFrame:SARectMake(47.5 + i * 125, 202, 30, 30)];
        iconImageV.image = [UIImage imageNamed:imageArr6[i]];
        [whiteView addSubview:iconImageV];
        
        UILabel *iconLab = [[UILabel alloc] initWithFrame:SARectMake(i * 125, 242, 125, 20)];
        iconLab.textColor = kBlackColor;
        iconLab.text = titleAr6[i];
        iconLab.font = kFont(15);
        iconLab.textAlignment = NSTextAlignmentCenter;
        [whiteView addSubview:iconLab];
        
        UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.tag = i + 15;
        iconBtn.frame = SARectMake(i * 125, 213, 125, 75);
        [iconBtn addTarget:self action:@selector(clickedIconBtn:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:iconBtn];
    }
    
    UIView *line3 = [[UIView alloc] initWithFrame:SARectMake(125, 41, 1, 227)];
    line3.backgroundColor = kLineColor;
    [whiteView addSubview:line3];
    
    UIView *line4 = [[UIView alloc] initWithFrame:SARectMake(250, 41, 1, 227)];
    line4.backgroundColor = kLineColor;
    [whiteView addSubview:line4];
    
    UIView *whiteView2 = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 273, kBaseScreenWidth, 268)];
    whiteView2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView2];
    
    UIView *buleView2 = [[UIView alloc] initWithFrame:SARectMake(20, 10, 4, 20)];
    buleView2.backgroundColor = kBuleColor;
    [whiteView2 addSubview:buleView2];
    
    UILabel *titleLab2 = [[UILabel alloc] initWithFrame:SARectMake(41, 0, 100, 40)];
    titleLab2.text = @"进出";
    titleLab2.textColor = kBlackColor;
    titleLab2.font = kFont(16);
    [whiteView2 addSubview:titleLab2];
    
    UIView *line5 = [[UIView alloc] initWithFrame:SARectMake(0, 40, kBaseScreenWidth, 1)];
    line5.backgroundColor = kLineColor;
    [whiteView2 addSubview:line5];
    
    NSArray *imageArr3 = @[@"SA_sales", @"SA_Warehousing", @"SA_inventory"];
    NSArray *titleAr3 = @[@"销售单据", @"入库单据", @"盘点单据"];
    for (int i = 0; i < 3; i++) {
        UIImageView *iconImageV = [[UIImageView alloc] initWithFrame:SARectMake(47.5 + i * 125, 50, 30, 30)];
        iconImageV.image =  [UIImage imageNamed:imageArr3[i]];
        [whiteView2 addSubview:iconImageV];
        
        UILabel *iconLab = [[UILabel alloc] initWithFrame:SARectMake(i * 125, 90, 125, 20)];
        iconLab.textColor = kBlackColor;
        iconLab.text = titleAr3[i];
        iconLab.font = kFont(15);
        iconLab.textAlignment = NSTextAlignmentCenter;
        [whiteView2 addSubview:iconLab];
        
        UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.tag = i + 6;
        iconBtn.frame = SARectMake(i * 125, 41, 125, 75);
        [iconBtn addTarget:self action:@selector(clickedIconBtn:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView2 addSubview:iconBtn];
    }
    
    UIView *line6 = [[UIView alloc] initWithFrame:SARectMake(0, 116, kBaseScreenWidth, 1)];
    line6.backgroundColor = kLineColor;
    [whiteView2 addSubview:line6];
    
    NSArray *imageArr4 = @[@"SA_Profit", @"SA_distribution", @"SA_cargo"];
    NSArray *titleAr4 = @[@"盈亏查询", @"配货单据", @"调货单据"];
    for (int i = 0; i < 3; i++) {
        UIImageView *iconImageV = [[UIImageView alloc] initWithFrame:SARectMake(47.5 + i * 125, 126, 30, 30)];
        iconImageV.image = [UIImage imageNamed:imageArr4[i]];
        [whiteView2 addSubview:iconImageV];
        
        UILabel *iconLab = [[UILabel alloc] initWithFrame:SARectMake(i * 125, 166, 125, 20)];
        iconLab.textColor = kBlackColor;
        iconLab.text = titleAr4[i];
        iconLab.font = kFont(15);
        iconLab.textAlignment = NSTextAlignmentCenter;
        [whiteView2 addSubview:iconLab];
        
        UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.tag = i + 9;
        iconBtn.frame = SARectMake(i * 125, 127, 125, 85);
        [iconBtn addTarget:self action:@selector(clickedIconBtn:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView2 addSubview:iconBtn];
    }
    
    UIView *line9 = [[UIView alloc] initWithFrame:SARectMake(0, 192, kBaseScreenWidth, 1)];
    line9.backgroundColor = kLineColor;
    [whiteView2 addSubview:line9];
    
    NSArray *imageArr5 = @[@"SA_Return", @"SA_CollectionPay", @"SA_Settlement"];
    NSArray *titleAr5 = @[@"退货单据", @"收款单据", @"结算单据"];
    for (int i = 0; i < 3; i++) {
        UIImageView *iconImageV = [[UIImageView alloc] initWithFrame:SARectMake(47.5 + i * 125, 202, 30, 30)];
        iconImageV.image = [UIImage imageNamed:imageArr5[i]];
        [whiteView2 addSubview:iconImageV];
        
        UILabel *iconLab = [[UILabel alloc] initWithFrame:SARectMake(i * 125, 240, 125, 20)];
        iconLab.textColor = kBlackColor;
        iconLab.text = titleAr5[i];
        iconLab.font = kFont(15);
        iconLab.textAlignment = NSTextAlignmentCenter;
        [whiteView2 addSubview:iconLab];
        
        UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        iconBtn.tag = i + 12;
        iconBtn.frame = SARectMake(i * 125, 213, 125, 85);
        [iconBtn addTarget:self action:@selector(clickedIconBtn:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView2 addSubview:iconBtn];
    }
    
    UIView *line7 = [[UIView alloc] initWithFrame:SARectMake(125, 41, 1, 227)];
    line7.backgroundColor = kLineColor;
    [whiteView2 addSubview:line7];
    
    UIView *line8 = [[UIView alloc] initWithFrame:SARectMake(250, 41, 1, 227)];
    line8.backgroundColor = kLineColor;
    [whiteView2 addSubview:line8];

    
    
}

@end
